package webDemo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet(name = "ServletDome01", value = "/ServletDome01")
public class ServletDome01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String method = request.getMethod();//获取请求方式
        System.out.println("请求方式："+method);
        String contextPath = request.getContextPath();//获取虚拟目录
        System.out.println("虚拟目录"+contextPath);
        StringBuffer requestURL = request.getRequestURL();//获取URL(统一资源定位符)
        System.out.println("URL(统一资源定位符)"+requestURL);
        String requestURI = request.getRequestURI();//获取URI(统一资源标识符)
        System.out.println("URI(统一资源标识符)"+requestURI);
        String queryString = request.getQueryString();//获取请求参数
        System.out.println("请求参数"+queryString);
        System.out.println("-----------------------------");
        String header = request.getHeader("user-agent");//获取请求头信息-浏览器版本user-agent
        System.out.println(header);
        System.out.println("-----------------------------");

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader reader = request.getReader();//获取字符流
        String s = reader.readLine();
        System.out.println(s);
    }
}